package base.java9_17;

/**
 * Sealed Classes在JDK15作为preview引入，在JDK16作为第二轮preview，在JDK17转正
 *
 * @author 王霄
 * @date 2021/9/27 10:27
 **/
public class SealedDemo {

    public static void main(String[] args) {

        A a = new A();
        A b = new B();
        A c = new C();
        A d = new D();
        a.run();
        b.run();
        c.run();
        d.run();
    }


    public static sealed class A permits B, C, D {
        public void run() {
            System.out.println("A");
        }
    }

    public static final class B extends A {
        @Override
        public void run() {
            System.out.println("B");
        }
    }

    public static final class C extends A {
        @Override
        public void run() {
            System.out.println("C");
        }
    }

    public static final class D extends A {
        @Override
        public void run() {
            System.out.println("D");
        }
    }
}
